#通过表格中的参数划分表格
import csv
def classify_by_parameter(input_file, sid_output_file, ssid_output_file):
    # 初始化两个列表来存储分类后的数据
    sid_data = []
    ssid_data = []
    
    # 读取输入文件
    with open(input_file, mode='r', encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile)
        
        # 确保字段名正确
        fieldnames = reader.fieldnames
        
        for row in reader:
            if row['参数'] == 'sid':
                sid_data.append(row)
            elif row['参数'] == 'ssid':
                ssid_data.append(row)
    
    # 写入sid类别的数据
    if sid_data:
        with open(sid_output_file, mode='w', encoding='utf-8', newline='') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            writer.writerows(sid_data)
    
    # 写入ssid类别的数据
    if ssid_data:
        with open(ssid_output_file, mode='w', encoding='utf-8', newline='') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            writer.writerows(ssid_data)
    
    print(f"分类完成！sid类别数据已保存到 {sid_output_file}")
    print(f"ssid类别数据已保存到 {ssid_output_file}")

# 使用示例
input_csv = 'GZ.csv'  # 替换为你的输入文件路径
sid_output = 'GZsid_categories.csv'      # sid类别输出文件
ssid_output = 'GZssid_categories.csv'    # ssid类别输出文件

classify_by_parameter(input_csv, sid_output, ssid_output)